# Responsability
# Create all the tasks that has to be done in mpi slaves.


TasksFactory <- setRefClass(    
  "tasksfactory"
  , fields = list(
      projectFolders="list"
    )
  , methods = list(
    initialize = function(...,projectFolders=list()) {
      
      .self$projectFolders <<- list()
      for (i in 1:4) {
        projectFolder <- paste("work",i,"/",sep="")
        .self$projectFolders[i] <<- projectFolder
      }

    },
    #
    #
    # Generate and prepare the first set of tasks for been executed in MPI slaves.
    #
    #
    generateTasks = function() {
      
      print("METHOD IN: generateTasks")
      
      tasks <- list()
      
      for (i in 1:length(projectFolders)) {
        
        tasks[[i]] <- list(model=Model(projectPath=projectFolders[[i]]), 
                           chainState=ChainState(id=i))
        
        utils <- ModelUtils(projectDir=projectFolders[[i]])
        utils$prepareProjectFolderAndFiles()
      }
      
      print("METHOD OUT: generateTasks")
      
      tasks
     }
    
  )#End methods List 
  
)#End RefClass



